﻿using System;
using System.Text.RegularExpressions;

namespace Read.Utility
{
	public class UVerify
	{
		private string Message = string.Empty;

		public UVerify Empty(string str, string message = "值不能为空")
		{
			if(!string.IsNullOrEmpty(str))
				this.Message = message;
			return this;
		}

		public UVerify GreaterThanZero(int val, string message = "值必须大于0")
		{
			if (val < 0)
				this.Message = message;
			return this;
		}

		public UVerify MinChar(string str, int len = 10, string message = "")
		{
			if (message == string.Empty)
				message = $"字数不能小于{len}个字符";

			if (str.Length < 10)
				this.Message = message;

			return this;
		}

		public UVerify IsPhone(string str, string message = "电话号码格式错误")
		{
			var reg = new Regex("^1\\d{10}$");
			if (reg.Match(str).Value == "")
				this.Message = message;
			return this;
		}

		public string Verify()
		{
			return Message;
		}
	}
}
